#include "odn_phys_PhysicalObject.h"

namespace ouden
{
	namespace physics
	{
		
		//Public
		
		//Destructor 
		virtual ODN_PhysicalObject::~ODN_PhysicalObject()
		{
			
			//Clean up dynamic memory of object 
			while (points.size()) { delete points.back(); points.pop_back(); }
			while (colliders.size()) { delete colliders.back(); colliders.pop_back(); }
			while (bones.size()) { delete bones.back(); bones.pop_back(); }
			//... 
			
		}
		
		//Update the object parts 
		virtual bool ODN_PhysicalObject::Update()
		{
			
			
			/*
			//Update all springs 
			for (int i=0;i<springs.size();i++) {
				springs[i]->Update();
			}*/
			
		}
		
		//Update all of the constraints of the object, including bones, restrictions and collision detection 
		bool ODN_PhysicalObject::satisfyConstraints()
		{
			
			//Iterate the constraint satisfying to increase accuracy 
			for (int j=0;j<CONSTRAINT_ITERATIONS;j++) {
				
				//Update all bones 
				for (int i=0;i<bones.size();i++) {
					bones[i]->Update();
				}
				
				//Update all restrictions  
				/*for (int i=0;i<restrictions.size();i++) {
					restrictions[i]->Update();
				}*/
				
			}
			
		};
		
		
		
		//Protected
		
		ODN_Point* ODN_PhysicalObject::addNewPoint(ODN_Point Point)
		{
			//Create a new object and use the copy constructor to make it a copy of the given object 
			//TODO: Check if this works 
			ODN_Point* NewPoint = new ODN_Point(Point);
			points.push_back(NewPoint);
			return NewPoint;	
		}
		
		//Private
		
		
		
	} //namespace physics
} //namespace ouden
